
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 09/25/2010 11:56:01
-- Generated from EDMX file: C:\skynet\Skynet.BusinessEntities\skynetlibrarymodel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [SkyNetLibrary];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Examen_CategoriaExamen]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Exams] DROP CONSTRAINT [FK_Examen_CategoriaExamen];
GO
IF OBJECT_ID(N'[dbo].[FK_ExamenXUsuario_Examen]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ExamByCustomers] DROP CONSTRAINT [FK_ExamenXUsuario_Examen];
GO
IF OBJECT_ID(N'[dbo].[FK_ExamenXUsuario_Usuarios]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ExamByCustomers] DROP CONSTRAINT [FK_ExamenXUsuario_Usuarios];
GO
IF OBJECT_ID(N'[dbo].[FK_Pregunta_Examen]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Questions] DROP CONSTRAINT [FK_Pregunta_Examen];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Alternatives]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Alternatives];
GO
IF OBJECT_ID(N'[dbo].[Customers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Customers];
GO
IF OBJECT_ID(N'[dbo].[ExamByCustomers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ExamByCustomers];
GO
IF OBJECT_ID(N'[dbo].[ExamCategories]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ExamCategories];
GO
IF OBJECT_ID(N'[dbo].[Exams]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Exams];
GO
IF OBJECT_ID(N'[dbo].[Helps]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Helps];
GO
IF OBJECT_ID(N'[dbo].[Kinds]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Kinds];
GO
IF OBJECT_ID(N'[dbo].[MethodAudits]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MethodAudits];
GO
IF OBJECT_ID(N'[dbo].[Questions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Questions];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Alternatives'
CREATE TABLE [dbo].[Alternatives] (
    [Id] uniqueidentifier  NOT NULL,
    [Data] uniqueidentifier  NOT NULL,
    [Answer] uniqueidentifier  NOT NULL,
    [Score] float  NOT NULL,
    [QuestionId] uniqueidentifier  NOT NULL,
    [TypeId] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'ExamByCustomers'
CREATE TABLE [dbo].[ExamByCustomers] (
    [Id] uniqueidentifier  NOT NULL,
    [Status] smallint  NOT NULL,
    [Duration] smallint  NOT NULL,
    [CustomerId] uniqueidentifier  NOT NULL,
    [ExamId] uniqueidentifier  NOT NULL,
    [ValidFrom] datetime  NOT NULL,
    [ValidTo] datetime  NOT NULL,
    [Score] float  NOT NULL
);
GO

-- Creating table 'ExamCategories'
CREATE TABLE [dbo].[ExamCategories] (
    [Id] uniqueidentifier  NOT NULL,
    [Title] varchar(500)  NOT NULL,
    [Description] varchar(4000)  NOT NULL,
    [OptimisticId] uniqueidentifier  NULL
);
GO

-- Creating table 'Exams'
CREATE TABLE [dbo].[Exams] (
    [Id] uniqueidentifier  NOT NULL,
    [Title] varchar(500)  NOT NULL,
    [Summary] varchar(max)  NULL,
    [CategoryExamId] uniqueidentifier  NOT NULL,
    [Attach] varbinary(max)  NULL
);
GO

-- Creating table 'Helps'
CREATE TABLE [dbo].[Helps] (
    [Id] uniqueidentifier  NOT NULL,
    [Title] varchar(2000)  NOT NULL,
    [Descriptioin] varchar(2000)  NULL,
    [Data] uniqueidentifier  NOT NULL,
    [TypeId] uniqueidentifier  NOT NULL,
    [QuestionId] uniqueidentifier  NULL
);
GO

-- Creating table 'Questions'
CREATE TABLE [dbo].[Questions] (
    [Id] uniqueidentifier  NOT NULL,
    [Data] uniqueidentifier  NOT NULL,
    [Category] varchar(2000)  NOT NULL,
    [ExamId] uniqueidentifier  NOT NULL,
    [TypeId] uniqueidentifier  NOT NULL,
    [Title] varchar(500)  NOT NULL
);
GO

-- Creating table 'Kinds'
CREATE TABLE [dbo].[Kinds] (
    [Id] uniqueidentifier  NOT NULL,
    [Title] varchar(200)  NOT NULL,
    [Description] varchar(2000)  NOT NULL
);
GO

-- Creating table 'Customers'
CREATE TABLE [dbo].[Customers] (
    [Id] uniqueidentifier  NOT NULL,
    [Name] varchar(256)  NULL,
    [LastName] varchar(256)  NULL,
    [BirthDate] datetime  NULL,
    [DocIden] varchar(50)  NULL,
    [PhotoId] uniqueidentifier  NULL,
    [MobilePhone] varchar(50)  NULL
);
GO

-- Creating table 'MethodAudits'
CREATE TABLE [dbo].[MethodAudits] (
    [Id] uniqueidentifier  NOT NULL,
    [method] varchar(256)  NULL,
    [className] varchar(512)  NULL,
    [module] varchar(512)  NULL,
    [username] varchar(256)  NULL,
    [solution] varchar(256)  NULL,
    [application] uniqueidentifier  NULL,
    [session] uniqueidentifier  NULL,
    [activity] uniqueidentifier  NULL,
    [operation] uniqueidentifier  NULL,
    [created] datetime  NULL,
    [owner] varchar(256)  NULL,
    [Description] varchar(1000)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Alternatives'
ALTER TABLE [dbo].[Alternatives]
ADD CONSTRAINT [PK_Alternatives]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ExamByCustomers'
ALTER TABLE [dbo].[ExamByCustomers]
ADD CONSTRAINT [PK_ExamByCustomers]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ExamCategories'
ALTER TABLE [dbo].[ExamCategories]
ADD CONSTRAINT [PK_ExamCategories]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Exams'
ALTER TABLE [dbo].[Exams]
ADD CONSTRAINT [PK_Exams]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Helps'
ALTER TABLE [dbo].[Helps]
ADD CONSTRAINT [PK_Helps]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Questions'
ALTER TABLE [dbo].[Questions]
ADD CONSTRAINT [PK_Questions]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Kinds'
ALTER TABLE [dbo].[Kinds]
ADD CONSTRAINT [PK_Kinds]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Customers'
ALTER TABLE [dbo].[Customers]
ADD CONSTRAINT [PK_Customers]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MethodAudits'
ALTER TABLE [dbo].[MethodAudits]
ADD CONSTRAINT [PK_MethodAudits]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [ExamId] in table 'ExamByCustomers'
ALTER TABLE [dbo].[ExamByCustomers]
ADD CONSTRAINT [FK_ExamenXUsuario_Examen]
    FOREIGN KEY ([ExamId])
    REFERENCES [dbo].[Exams]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ExamenXUsuario_Examen'
CREATE INDEX [IX_FK_ExamenXUsuario_Examen]
ON [dbo].[ExamByCustomers]
    ([ExamId]);
GO

-- Creating foreign key on [CategoryExamId] in table 'Exams'
ALTER TABLE [dbo].[Exams]
ADD CONSTRAINT [FK_Examen_CategoriaExamen]
    FOREIGN KEY ([CategoryExamId])
    REFERENCES [dbo].[ExamCategories]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Examen_CategoriaExamen'
CREATE INDEX [IX_FK_Examen_CategoriaExamen]
ON [dbo].[Exams]
    ([CategoryExamId]);
GO

-- Creating foreign key on [Id] in table 'Questions'
ALTER TABLE [dbo].[Questions]
ADD CONSTRAINT [FK_Pregunta_Examen]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Exams]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [CustomerId] in table 'ExamByCustomers'
ALTER TABLE [dbo].[ExamByCustomers]
ADD CONSTRAINT [FK_ExamenXUsuario_Usuarios]
    FOREIGN KEY ([CustomerId])
    REFERENCES [dbo].[Customers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ExamenXUsuario_Usuarios'
CREATE INDEX [IX_FK_ExamenXUsuario_Usuarios]
ON [dbo].[ExamByCustomers]
    ([CustomerId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------